<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增报价实体')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />

    <link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
    <link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
    <style>
                   #ddsas.hide{opacity: 0;}

                 </style>
</head>

<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-offerinfo-add">
            <!--<div class="form-group">    -->
                <!--<label class="col-sm-3 control-label">竞价信息表ID：</label>-->
                <!--<div class="col-sm-8">-->
            <input name="bidInfoId" class="form-control" type="hidden" th:value="*{bidInfoId}">
                <!--</div>-->
            <!--</div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">需求数量：</label>
                <div class="col-sm-8">
                    <input name="count" class="form-control" readonly th:value="*{count}" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商品要求：</label>
                <div class="col-sm-8">
                    <textarea name="demand" class="form-control" readonly  rows="10" th:text="*{demand}" ></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商品：</label>
                <div class="col-sm-8">
                    <div th:style="'display:' + @{(*{count} ? 'none' : 'inline-block')} + ''">

                    <div id="ddsas" th:each="goods:${sysGoodparameters}" >
                        <input type="hidden" id="gpdid" th:text="${goods.goodParameterId}" th:value="${goods.goodParameters}" />
                        <input type="hidden" id="qtmid" th:text="${goods.goodParameterId}"  th:value="${goods.goodPrice}"/>
                    </div>
                    </div>
                    <select name="goodParameterId" class="form-control m-b" id="goodParameterId" th:onchange="'javascript:changeGood(this);'">
                        <option th:each="goodParameter : ${sysGoodparameters}" th:text="${goodParameter.goodName}" th:value="${goodParameter.goodParameterId}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">报价参数：</label>
                <div class="col-sm-8">
                    <textarea name="offerParameter" id="offerParameter" class="form-control" readonly rows="10"></textarea>
                    <!--<input id="offerParameter" name="offerParameter" type="hidden">-->
                    <!--<div class="shangpinmiaoshu"></div>-->

                </div>
            </div>
            <div class="form-group options">
                <label class="col-sm-3 control-label">配选件：</label>
                <div class="col-sm-1" style="padding:0px;">
                    <div class="checkbox" style="padding-top:5px;">
                        <label>
                            <input type="checkbox" name="peixuans">
                        </label>
                    </div>
                </div>
                <div class="col-sm-3" style="padding:0px;">
                    <input name="optionsName" class="form-control" readonly type="text" placeHolder="请输入配选件名" maxlength="20" style="width: 90%;" />
                </div>
                <div class="col-sm-3" style="padding:0px;">
                    <input name="variablePrice" type="text" readonly placeHolder="请输入差价(元)" maxlength="9" class="form-control number" style="width: 75%;" onblur="priceChange()"/>
                </div>
                <div class="col-sm-1" style="padding-top:8px;">
                    (元)
                </div>

            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">报价金额：</label>
                <div class="col-sm-8">
                    <input name="offerAmount" class="form-control" type="text">
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
    <script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
    <script th:inline="javascript">
        var prefix = ctx + "system/offerinfo"

        $("#form-offerinfo-add").validate({
            focusCleanup: true
        });
        function changeGood(obj){
            var goodPatameterId = $(obj).val();
            var vals = $("#ddsas input");
            var val1 = vals[0].val();
           alert(vals.length);

        }
        function submitHandler() {
            var attribute3='';
            if ($.validate.form()) {
//                var sHTML = $('.shangpinmiaoshu').summernote('code');
//                $("#offerParameter").val(sHTML);
                var length=$("input[name='peixuans']:checked").length;
                $("input[name='peixuans']:checked").each(function(index,item){
                    if(index==length-1){
                        attribute3+=$(this).val()
                    }else{
                        attribute3+=$(this).val()+','
                    }

                })
                console.log(attribute3);
                $.operate.save(prefix + "/add", $('#form-offerinfo-add').serialize()+'&attribute3='+attribute3);
            }
        }
        function changeGood1(){

            var data = [[${sysGoodparameters}]];
            var goodPrameterId = $("#goodParameterId option:selected").val();
            if(data instanceof Array && data.length>0){
                for(var i=0;i<data.length;i++){
                    if(data[i].goodParameterId==goodPrameterId){
                        var str="";
                        var jsonStr=JSON.parse(data[i].goodParameters);
                        if(jsonStr.pmchicun!=""||jsonStr.pmchicun!=null||jsonStr.pmchicun!=undefined){
                            str+='屏幕尺寸:'+jsonStr.pmchicun+","
                        }
                        if(jsonStr.neicun!=""||jsonStr.neicun!=null||jsonStr.neicun!=undefined){
                            str+='内存:'+jsonStr.neicun+","
                        }
                        if(jsonStr.chuliqi!=""||jsonStr.chuliqi!=null||jsonStr.chuliqi!=undefined){
                            str+='处理器:'+jsonStr.chuliqi+","
                        }
                        if(jsonStr.xianka!=""||jsonStr.xianka!=null||jsonStr.xianka!=undefined){
                            str+='显卡:'+jsonStr.xianka+","
                        }
                        if(jsonStr.xianshiqi!=""||jsonStr.xianshiqi!=null||jsonStr.xianshiqi!=undefined){
                            str+='显示器:'+jsonStr.xianshiqi+","
                        }
                        if(jsonStr.yingpan!=""||jsonStr.yingpan!=null||jsonStr.yingpan!=undefined){
                            str+='硬盘:'+jsonStr.yingpan+","
                        }
                        if(jsonStr.caozuoxitong!=""||jsonStr.caozuoxitong!=null||jsonStr.caozuoxitong!=undefined){
                            str+='操作系统:'+jsonStr.caozuoxitong+","
                        }
                        if(jsonStr.bjbzhongliang!=""||jsonStr.bjbzhongliang!=null||jsonStr.bjbzhongliang!=undefined){
                            str+='笔记本重量:'+jsonStr.bjbzhongliang+","
                        }
                        if(jsonStr.other!=""||jsonStr.other!=null||jsonStr.other!=undefined){
                            str+='参数:'+jsonStr.other
                        }
                        $("#offerParameter").text(str);

                        //配选件处理
                        var withOptions=data[i].peixuanjianList;
                        var html="";
                        console.log(withOptions);
                        if(withOptions instanceof Array &&withOptions.length>0){
                            $("input[name='peixuans']:first").val(withOptions[0].peiXuanJianId);
                            $("input[name='optionsName']:first").val(withOptions[0].goodName);
                            $("input[name='variablePrice']:first").val(withOptions[0].attribite1);
                            for(var i=1;i<withOptions.length;i++){
                                html+= '' +
                                        '<div class="form-group options" >' +
                                        '<label class="col-sm-3 control-label">&nbsp;</label>' +
                                        '<div class="col-sm-1" style="padding:0px;">'+
                                            '<div class="checkbox" tyle="padding-top:5px;">'+
                                                '<label>'+
                                                    '<input type="checkbox" name="peixuans" value="'+withOptions[i].peiXuanJianId+'">'+
                                                '</label>'+
                                            '</div>'+
                                        '</div>'+
                                        '<div class="col-sm-3" style="padding:0px;"><input readonly name="optionsName" class="form-control" type="text" placeHolder="请输入配选件名" maxlength="60" style="width: 90%;" value="'+withOptions[i].goodName+'" /></div>' +
                                        '<div class="col-sm-3" style="padding:0px;"><input readonly name="variablePrice" class="form-control" type="text" placeHolder="请输入差价" maxlength="9" class="number"  style="width: 75%;"   onblur="priceChange()" value="'+withOptions[i].attribite1+'" /></div>' +
                                        '<div class="col-sm-1" style="padding-top:8px;">(元)</div>'+
                                        '</div>' +
                                '</div>';
                            }
                            $("div.options:last").after(html);
                        }
                    }
                }
            }


        }
        $("input[name='crateTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        $('.shangpinmiaoshu').summernote({
            height: '220px',
            lang: 'zh-CN',
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });
        // 上传文件
        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }
    </script>
</body>
</html>